<!-- 下载列表 -->
<template>
  <recycle-scroller ref="imgListRef" class="content-list" :items="dataList" :item-size="71" key-field="id" v-slot="{ item }">
    <div class="content-list-item">
      <div class="content-list-item-content">
        <div class="content-info">
          <div class="title-wrap">
            <div class="title">
              <i class="iconfont icon-folder-3-line"></i>
              <p :title="item.name">{{ item?.name }}</p>
            </div>
            <p :title="item.location">{{ item?.location }}</p>
          </div>
          <div class="status">
            <p v-if="item.status === 0" class="loading">资源准备中...</p>
            <p v-else-if="item.status === 1" class="successful">资源准备成功</p>
            <p v-else-if="item.status === 2" class="failed">资源准备失败</p>
          </div>
          <div class="hover-status">
            <a-button v-if="item.status === 1" class="down-btn" size="small" type="default" @click="handleDownload(item)">下载</a-button>
            <a-button v-if="item.status !== 0" type="text" class="icon-only-btn" @click="handleRemoveItem(item)">
              <i class="iconfont icon-close-line"></i>
            </a-button>
          </div>
        </div>
      </div>
    </div>
  </recycle-scroller>
  <div class="clear-all" @click="handleClearAll"><i class="iconfont icon-delete-bin-fill"></i>清空</div>
</template>

<script setup lang="ts">
  import { LocalFileInfo } from '../types/index'

  type ExportListProps = {
    dataList: LocalFileInfo[]
  }

  withDefaults(defineProps<ExportListProps>(), {
    dataList: () => []
  })

  const emits = defineEmits<{
    (e: 'clear-all'): void
    (e: 'download', fileInfo: LocalFileInfo): void
    (e: 'remove', fileInfo: LocalFileInfo): void
  }>()

  const handleClearAll = () => {
    emits('clear-all')
  }

  const handleRemoveItem = (item: LocalFileInfo) => {
    emits('remove', item)
  }

  const handleDownload = async (item: LocalFileInfo) => {
    emits('download', item)
  }
</script>

<style lang="less" scoped>
  @import '../style/common.less';

  .content-list {
    display: flex;
    overflow: auto;
    padding: 10px 24px 0;
    width: 100%;
    flex: 1;
    border-top: 1px solid @border1;
    flex-direction: column;
    // min-height: 0;

    .content-list-item {
      width: 100%;
      border-bottom: 1px solid @border1;

      &:last-child {
        border-bottom: none;
      }

      .content-list-item-content {
        padding: 4px 8px;
        margin: 10px 0;
        width: 100%;
        background: #fff;
        cursor: pointer;

        &:hover {
          background: rgba(0, 0, 0, 0.05);
          border-radius: 2px;

          .content-info .status {
            display: none;
          }

          .content-info .hover-status {
            display: flex;
          }
        }

        .content-info {
          display: flex;
          justify-content: space-between;
          align-items: center;
          width: 100%;

          .title-wrap {
            flex: 1;
            min-width: 0;

            .title {
              display: flex;
              align-items: center;
              width: 100%;
              font-size: 14px;
              color: @text01;
              line-height: 22px;

              > i {
                display: block;
                margin-right: 4px;
                color: @text04;
              }

              > p {
                .elliptical-1();
              }
            }

            > p {
              font-size: 12px;
              font-weight: 400;
              line-height: 20px;
              color: @text03;
              .elliptical-1();
            }
          }

          .status {
            text-align: end;

            .success {
              color: @success;
            }

            > p {
              font-size: 12px;
              font-weight: 400;
              line-height: 20px;
            }

            .loading {
              color: @text04;
            }

            .failed {
              color: @danger;
            }

            .successful {
              color: @success;
            }
          }

          .down-btn {
            display: flex;
            justify-content: center;
            align-items: center;
            width: 48px;
            height: 24px;
            font-size: 12px;
            font-weight: 400;
          }

          .hover-status {
            display: none;
            gap: 0 4px;
          }
        }
      }

      .content-list-item-file {
        display: flex;
        align-items: center;
        padding: 0 8px 0 24px;
        margin: 14px 0;
        height: 24px;
        gap: 0 4px;

        > p {
          font-size: 14px;
          font-weight: 400;
          line-height: 22px;
          .elliptical-1();
        }

        &:hover {
          background: rgba(0, 0, 0, 0.05);
          border-radius: 2px;

          .icon-only-btn {
            display: flex;
          }
        }

        .icon-only-btn {
          display: none;
          margin-left: auto;
        }
      }

      .collapse {
        padding: 14px 0;
      }

      .collapse-header {
        display: flex;
        align-items: center;
        padding-right: 8px;
        height: 24px;
        cursor: pointer;

        &:hover {
          background: rgba(0, 0, 0, 0.05);
          border-radius: 2px;

          .icon-only-btn {
            display: flex;
          }
        }

        .icon-caret-down-wrap {
          width: 24px;
          height: 24px;
          line-height: 24px;
          text-align: center;

          > i {
            font-size: 12px;
          }

          &.rotate {
            transform: rotate(-90deg);
          }
        }

        > i {
          margin-right: 4px;
        }

        .icon-only-btn {
          display: none;
          margin-left: auto;
        }
      }
    }
  }
</style>
